package cn.admobiletop.adsuyi.adapter.toutiao.data;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.view.View;

import cn.admobiletop.adsuyi.ad.data.ADSuyiInterstitialAdInfo;
import cn.admobiletop.adsuyi.ad.listener.ADSuyiInterstitialAdListener;

/**
 * @author ciba
 * @description 插屏广告内容对象
 * @date 2020/4/3
 */
public class InterstitialAdInfo extends TTNativeExpressAdInfo<ADSuyiInterstitialAdListener> implements ADSuyiInterstitialAdInfo {
    private boolean hasShown;
    private Handler handler = new Handler(Looper.getMainLooper());

    public InterstitialAdInfo(Activity activity, String platformPosId) {
        super(activity, platformPosId);
    }

    @Override
    public void showInterstitial(Activity activity) {
        if (activity != null
                && !isReleased()
                && isReady()
                && getAdapterAdInfo() != null
                && !hasShown()
                && !hasExpired()) {
            hasShown = true;
            getAdapterAdInfo().showInteractionExpressAd(activity);
        }
    }

    @Override
    public boolean hasShown() {
        return hasShown;
    }

    @Override
    public boolean hasExpired() {
        return false;
    }

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public void onCloseClick(View view) {
//        if (handler != null) {
//            handler.post(new Runnable() {
//                @Override
//                public void run() {
//                    if (getAdListener() != null) {
//                        getAdListener().onAdClose(InterstitialAdInfo.this);
//                    }
//                }
//            });
//        }
    }

    @Override
    public void releaseAdapter() {
        super.releaseAdapter();
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
            handler = null;
        }
    }
}
